{extend name="../admin/common/base" /}
{block name="nav_title"}
<a href="{:url('addNews')}" id="addkw" class="layui-btn layui-btn-normal layui-btn-sm rha-nav-title">增加图文</a>
{/block}
{block name="body"}
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
    <ul class="layui-tab-title">
        <a href="{:url('newsList',['type'=>4])}"><li {eq name="intype" value="4" } class="layui-this" {/eq}>活动</li></a>
        <a href="{:url('newsList',['type'=>3])}"><li {eq name="intype" value="3" } class="layui-this" {/eq}>多图文</li></a>
        <a href="{:url('newsList',['type'=>2])}"><li {eq name="intype" value="2" } class="layui-this" {/eq}>单图文</li></a>
        <a href="{:url('newsList',['type'=>1])}"><li {eq name="intype" value="1" } class="layui-this" {/eq}>文本</li></a>
    </ul>
    <div class="layui-tab-content">
        {switch name="intype"}
        {case value="3"}
        <div class="layui-tab-item  layui-show">
            <div class="layui-row">
                {volist name="data" id="val"}
                <div class="layui-col-md4 rhaphp-media-news">
                    <div class="media-news-body">
                        <div class="media-news-time">
                            发布时间：{:date('Y-m-d : h:i',$val.create_time)}
                            &nbsp;&nbsp;&nbsp;状态:{if condition="$val.status_type eq '0'"}未上传{elseif condition="$val.status_type eq '1'"/}已上传{else/}已群发{/if}
                        </div>
                        <span style="display: block;">
                            {volist name="val.list" id="item" offset="0" length="1"}
                            <div class="media-news-content">
                                <div class="media-news-desc"><p
                                        class="media-news-desc-sp">{$item.title}</p></div>
                                <img class="media-news-img"
                                     src="{$item.cover}">
                            </div>
                             {/volist}
                        </span>
                        <div>
                            <ul>
                                {volist name="val.list" id="item" offset="1" length="10"}
                                <li>
                                    <div class="mdedia-news-lists-box">
                                        <div class="media-news-title-box layui-col-md9">
                                            {$item.title}
                                        </div>
                                        <div class="media-news-img-box layui-col-md3"><img class="media-news-lists-img" src="{$item.cover}">
                                        </div>
                                    </div>
                                </li>
                                {/volist}
                            </ul>
                        </div>
                        <div class="media-news-item-type2">
                            <div class="layui-btn-group media-news-btn">
                                <button onclick="selectMp('{$val.news_id}')" class="layui-btn layui-btn-primary layui-btn-sm">
                                    <i class="layui-icon">&#xe609;</i>
                                    选择公众号群发
                                </button>
                                <button onclick="Preview('{$val.news_id}')" class="layui-btn layui-btn-primary layui-btn-sm">
                                    <i class="layui-icon">&#xe610;</i>
                                    预览
                                </button>

                                <a class="layui-btn layui-btn-primary layui-btn-sm" href="{:url('editNews',['news_id'=>$val.news_id,'type'=>'3'])}">
                                    <i class="layui-icon">&#xe642;</i>
                                    编辑&删
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
                {/volist}
                    </div>
                </div>
            </div>
        </div>
        {/case}
{case value="4"}
<div class="layui-tab-item  layui-show">
    <div class="layui-row">
        {volist name="data" id="val"}
        <div class="layui-col-md4 rhaphp-media-news">
            <div class="media-news-body">
                <div class="media-news-time">
                    发布时间：{:date('Y-m-d : h:i',$val.create_time)}
                    &nbsp;&nbsp;&nbsp;状态:{if condition="$val.status_type eq '0'"}未上传{elseif condition="$val.status_type eq '1'"/}已上传{else/}已群发{/if}
                </div>
                <span style="display: block;">
                                    {volist name="val.list" id="item" offset="0" length="1"}
                                    <div class="media-news-content">
                                        <div class="media-news-desc"><p
                                                class="media-news-desc-sp">{$item.title}</p></div>
                                        <img class="media-news-img"
                                             src="{$item.cover}">
                                    </div>
                                     {/volist}
                                </span>
                <div>
                    <ul>
                        {volist name="val.list" id="item" offset="1" length="10"}
                        <li>
                            <div class="mdedia-news-lists-box">
                                <div class="media-news-title-box layui-col-md9">
                                    {$item.title}
                                </div>
                                <div class="media-news-img-box layui-col-md3"><img class="media-news-lists-img" src="{$item.cover}">
                                </div>
                            </div>
                        </li>
                        {/volist}
                    </ul>
                </div>
                <div class="media-news-item-type2">
                    <div class="layui-btn-group media-news-btn">
                        <button onclick="selectMp('{$val.news_id}')" class="layui-btn layui-btn-primary layui-btn-sm">
                            <i class="layui-icon">&#xe609;</i>
                            选择公众号群发
                        </button>
                        <button onclick="Preview('{$val.news_id}')" class="layui-btn layui-btn-primary layui-btn-sm">
                            <i class="layui-icon">&#xe610;</i>
                            预览
                        </button>

                        <a class="layui-btn layui-btn-primary layui-btn-sm" href="{:url('editNews',['news_id'=>$val.news_id,'type'=>'4'])}">
                            <i class="layui-icon">&#xe642;</i>
                            编辑&删
                        </a>
                    </div>
                </div>
            </div>
        </div>
        {/volist}
    </div>
</div>
</div>
</div>
{/case}
        {case value="2"}
        <div class="layui-tab-item  layui-show">
            <div class="layui-row">
                {volist name="data" id="val"}
                <div class="layui-col-md4 rhaphp-media-news">
                    <div class="media-news-body">
                        <div class="media-news-time">
                            发布时间：{:date('Y-m-d : h:i',$val.create_time)}
                            &nbsp;&nbsp;&nbsp;状态:{if condition="$val.status_type eq '0'"}未上传{elseif condition="$val.status_type eq '1'"/}已上传{else/}已群发{/if}
                        </div>
                        <span style="display: block;">
                                    {volist name="val.list" id="item" offset="0" length="1"}
                                    <div class="media-news-content">
                                        <div class="media-news-desc"><p
                                                class="media-news-desc-sp">{$item.title}</p></div>
                                        <img class="media-news-img"
                                             src="{$item.cover}">
                                    </div>
                                     {/volist}
                                </span>
                        <div>
                            <ul>
                                {volist name="val.list" id="item" offset="1" length="10"}
                                <li>
                                    <div class="mdedia-news-lists-box">
                                        <div class="media-news-title-box layui-col-md9">
                                            {$item.title}
                                        </div>
                                        <div class="media-news-img-box layui-col-md3"><img class="media-news-lists-img" src="{$item.cover}">
                                        </div>
                                    </div>
                                </li>
                                {/volist}
                            </ul>
                        </div>
                        <div class="media-news-item-type2">
                            <div class="layui-btn-group media-news-btn">
                                <button onclick="selectMp('{$val.news_id}')" class="layui-btn layui-btn-primary layui-btn-sm">
                                    <i class="layui-icon">&#xe609;</i>
                                    选择公众号群发
                                </button>
                                <button onclick="Preview('{$val.news_id}')" class="layui-btn layui-btn-primary layui-btn-sm">
                                    <i class="layui-icon">&#xe610;</i>
                                    预览
                                </button>

                                <a class="layui-btn layui-btn-primary layui-btn-sm" href="{:url('editNews',['news_id'=>$val.news_id,'type'=>'2'])}">
                                    <i class="layui-icon">&#xe642;</i>
                                    编辑&删
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
                {/volist}
            </div>
        </div>
        </div>
        </div>
        {/case}
{case value="1"}
<div class="layui-tab-item  layui-show">
    <div class="layui-row">
        {volist name="data" id="val"}
        <div class="layui-col-md4 rhaphp-media-news">
            <div class="media-news-body">
                <div class="media-news-time">
                    发布时间：{:date('Y-m-d : h:i',$val.create_time)}
                    &nbsp;&nbsp;&nbsp;状态:{if condition="$val.status_type eq '3'"}已群发{else/}未群发{/if}
                </div>
                <div>
                    {$val.title}
                </div>
                <div class="media-news-item-type2">
                    <div class="layui-btn-group media-news-btn">
                        <button onclick="selectMp('{$val.news_id}')" class="layui-btn layui-btn-primary layui-btn-sm">
                            <i class="layui-icon">&#xe609;</i>
                            选择公众号群发
                        </button>
                        <button onclick="Preview('{$val.news_id}')" class="layui-btn layui-btn-primary layui-btn-sm">
                            <i class="layui-icon">&#xe610;</i>
                            预览
                        </button>

                        <a class="layui-btn layui-btn-primary layui-btn-sm" href="{:url('editNews',['news_id'=>$val.news_id,'type'=>'1'])}">
                            <i class="layui-icon">&#xe642;</i>
                            编辑&删
                        </a>
                    </div>
                </div>
            </div>
        </div>
        {/volist}
    </div>
</div>
</div>
</div>
{/case}
    {/switch}

<form id="select-wrap" class="layui-form" action="" style="display: none">
    <div class="layui-form-item">
        <div class="layui-inline">
            <div class="layui-form-item">
                <label class="layui-form-label">公众号</label>
                <div class="layui-input-block ">
                    <div class="select-allmp">
                        <input type="checkbox"  title="全选公众号" lay-skin="primary" lay-filter="allChoose" id="selectAllMp">
                    </div>
                    {volist name="mpList" id="mp"}
                    <div class="select-mplist">
                        <div class="mp-logo">
                            <div class="logo-left">
                                <img src="{$mp.logo}">
                            </div>
                        </div>
                        <div class="logo-right">
                            <p class="p1">{$mp.name}</p>
                            <p class="p2">类型：{$mp.type_name}</p>
                        </div>
                        <input type="checkbox" name="select-mp" class="select-mp" value="{$mp.id}"  lay-ignore>
                    </div>
                    {/volist}

                </div>
            </div>
        </div>
    </div>

</form>
<div style="clear: both">{$page|raw}</div>


<script>
    layui.use(['layer'],function () {
        var layer=layui.layer;
    })


    function Preview(news_id) {


        layer.prompt({title: '请输入发送预览者微信号', formType: 0}, function(wxid, index){
            layer.close(index);
            var l_index=layer.load(1)
            $.post("{:url('newsPreview')}",{news_id:news_id,wxid:wxid},function (res) {
                if(res.status==1){
                    layer.msg(res.msg);
                }else{
                    layer.alert(res.msg);
                }
                layer.close(l_index);
                return false;
            }).error(function (res) {
                layer.close(l_index);
                layer.alert('服务出错');
            })
        });
    }




    layui.use('form', function () {
        var form = layui.form;
        form.on('checkbox(allChoose)', function(data){

            if($(data.elem).prop("checked")) {

                $('.select-mplist').addClass('on');
                $('.select-mp').prop('checked', true);

            }else{
                $('.select-mplist').removeClass('on');
                $('.select-mp').prop('checked',false);
            }
            form.render('checkbox');
        });
        $(function () {
            $('.select-mp').change(function () {
                if($(this).prop("checked")){
                    $(this).parent('.select-mplist').addClass('on');
                }else{
                    $(this).parent('.select-mplist').removeClass('on');
                }
            });

        })
    });

    function selectMp(news_id){
            //Mp_json1 = JSON.parse(Mp_json);
//            var str = '<form class="layui-form" action="">';
//
//            $.each(Mp_json1,function (k,Mp) {
//
//                    str += '<div class="select-mplist">'
//                        + '<div class="logo-left">'
//                        + '<img src="'+Mp.logo+'">'
//                        + ' </div>'
//                        + '  </div>'
//                        + '  <div class="logo-right">'
//                        + ' <p class="p1">'+Mp.name+'</p>'
//                        + ' <p class="p2">类型：'+Mp.name+'</p>'
//                        + ' </div>'
//                        + '<input type="checkbox" id="Mp'+Mp.id+'" name="select-mp[]" class="select-mp"  value="'+Mp.id+'" >'
//                        + ' </div>'
//                    ;
//            });
//
//
//            str+="</form>";
            layui.use(['layer','form'], function(){

                var layer = layui.layer;
                var title = '选择公众号';

                layer.open({
                    title:title,
                    type: 1,
                    area: '810px',
                    content: $('#select-wrap'),
                    btn: ['确认', '取消']
                    ,yes: function(index, layero){

                        var selected_Mps = $("input[name='select-mp']:checked");

                        var  selected_ids = '';
                        if(selected_Mps.length > 0){
                            var selected_id_arr = [];
                            selected_Mps.each(function () {
                                selected_id_arr.push($(this).val());
                            });
                            selected_ids = selected_id_arr.join(',');

                        }else{
                            layer.alert('请选择公众号');
                        }

                        layer.confirm('主人，确定要群发了吗？', {
                            btn: ['确定','取消']
                        }, function(){
                            var l_index=layer.load(1);
                            $.post("{:url('sendall')}",{mp_ids:selected_ids,news_id:news_id},function (res) {
                                if(res.status==1){

                                    layer.msg(res.msg);
                                }else{

                                    layer.alert(res.msg);
                                }
                                layer.close(l_index);
                                return false;
                            }).error(function (res) {
                                layer.close(l_index);
                                layer.alert('服务出错');
                            })
                        })

                    }
                    ,btn2: function(index, layero){
                        layer.close(index);


                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                    ,cancel: function(){
                        //右上角关闭回调

                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                });
                var form = layui.form;
                form.render('checkbox');

            });

    }

</script>
{/block}